/**
 * Created by user on 2018/5/22.
 */
import React, { Component } from 'react'
import { connect } from 'react-redux'
import OnlineTeacherItem from './onlineTeacherItem'
import { cloneObj } from '../../utils/Global'

class ReplayOnlineTeacher extends Component {
  renderItem() {
    const list = []
    const { teachers } = this.props
    var _tea = []
    for (let _ in teachers) {
      var t = cloneObj(teachers[_])
      t.headimgurl = t.headimg
      _tea.push(t)
    }
    _tea.map((tea, index) => {
      list.push(
        <OnlineTeacherItem teacher={tea} key={index} index={index} />
      )
    })
    return list
  }
  render() {
    const { showDm, screen } = this.props
    let dmClass = showDm && (screen === 0 || screen === 5)
    return (
      <div className={`online_teacher_con ${dmClass ? 'showDm' : ''}`}>
        {this.renderItem()}
      </div>
    )
  }
}
const mapStateToProps = (state) => {
  return {
    teachers: state.MainScreenState.teachers,
    screen: state.MainScreenState.screen,
    showDm: state.DmState.show
  }
}

export default connect(mapStateToProps)(ReplayOnlineTeacher)
